
function badDummy(){return false;}
function dummyFunc(){return true;}

/**************** BEGIN Standard functions for Dialog/window**********************/
	
	var moveableTopZ = 100;
	var debugTopZ = 10000;
	var movingItem = null;
	var showWindowContentsWhileDragging = false;
	var disableSelects = new Array();
	var dialogArgs = null;

function getDialog()
{
	dialogObj = document.getElementById("MsgDialog");
	if(dialogObj==null)
	{ 
		alert ("MsgDialog is undefine!");
		return ;
	}
	return dialogObj;
}

function showWindow(dialogId,dialogTitle,dialogWidth,dialogHeight)
{

	var dialogObj = window.document.getElementById(dialogId);
	if (dialogObj)
	{
		dialogObj.onselectstart=badDummy;
		setWindowTitle(dialogObj,dialogTitle);
	
		// get height, width of total client area and dialog
		var cHeight = document.body.offsetHeight;
		var cWidth = document.body.offsetWidth;
		
		// scroll offset makes sure popup still appears in middle of visible area if page is scrolled
		var scrolloffset = window.document.body.scrollTop;
		dialogHeight = (dialogHeight==""||dialogHeight==null)? 360: dialogHeight;
		dialogWidth = (dialogWidth==""||dialogWidth==null)? 320: dialogWidth;	
		
		dialogObj.style.width = dialogWidth;
		dialogObj.style.height = dialogHeight;
		
		var left = (cWidth - dialogWidth) / 2;
		var top = (cHeight - dialogHeight) / 4 + scrolloffset;		
		dialogObj.style.left = left;
		dialogObj.style.top = top;

		//dialogObj.style.display = "inline";
		dialogObj.style.visibility = "visible";
		
		ifrShim = document.createElement("<iframe id='ifrShim' src='javascript:false;' scrolling='no' frameborder='0' style='position:absolute; top:0px; left:0px;filter=progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);'></iframe>");	
		if(ifrShim)
		{
			dialogObj.ifrShim = ifrShim;
			dialogObj.ifrShim.style.width = dialogObj.offsetWidth;
		    dialogObj.ifrShim.style.height = dialogObj.offsetHeight;
			dialogObj.ifrShim.style.top = dialogObj.style.top;
		    dialogObj.ifrShim.style.left = dialogObj.style.left ;
		    dialogObj.ifrShim.style.zIndex = dialogObj.style.zIndex - 1;
		    dialogObj.ifrShim.style.visibility = "visible";
		    document.body.insertAdjacentElement("BeforeEnd",dialogObj.ifrShim);		   
		}				
	}
	//document.close();
}

function setWindowTitle(dialogObj,dialogTitle)
{

	var titleObj = walkForPart(dialogObj,"dialogtitle");
	if(titleObj!=null) 
	{
		if(dialogTitle!="" && (typeof dialogTitle!="undefined")) 
		{
			titleObj.innerText=dialogTitle;
		}else
		{
			titleObj.innerText="default Dialog title";
		}
	}
}

function hideWindow(dialogId)
{
	var dialogObj = window.document.getElementById(dialogId);
	if(dialogObj)
		//dialogObj.style.display = "none";
		dialogObj.style.visibility = "hidden";
	if(dialogObj.ifrShim)
		dialogObj.ifrShim.removeNode(true);
	document.close();
}

function showDialog(URL,dialogArguments,dialogTitle,dialogWidth,dialogHeight)
{	
	setDialogArguments(dialogArguments)		
	document.getElementById("commframe1").contentWindow.document.write();
	document.getElementById("commframe1").contentWindow.document.close();	
	comSubmit = comSubmit_GetForm();
	comSubmit.action = URL;
	comSubmit.target="commframe1";
	comSubmit.submit();
	dialogId = getDialog().id;	
	showWindow(dialogId,dialogTitle,dialogWidth,dialogHeight);
	showWait(dialogId);
	disableDialogUnderObjs();	
}

function hideDialog()
{
	dialogId = getDialog().id;
	hideWindow(dialogId);
	hideWait(dialogId);
	ableDialogUnderObjs();	
}

function hideWait(id)
{	
	
	dialogId = id;
	
	if(dialogId!=''&& dialogId!=null)
	{
		
		wait = document.getElementById(dialogId+"_waitLayer");
		if(wait)
			wait.removeNode(true);
	}
	
}
	
function showWait(ownerDialogId)
{	
	dialogId = ownerDialogId;
	dialog=null;
	
	IMAGE_PATH="../images/"
	waitImage = "wait_clear.gif";

	wait = document.createElement("<img class='waitimage' style='position:absolute;left:0px;top:0px' oncontextmenu='event.returnValue=false;' src='"+IMAGE_PATH+waitImage+"'>");		
	dialog = document.getElementById(dialogId);
		
	document.body.style.overFlow="hidden";
	if(wait)
	{
		wait.style.cursor="wait";
		wait.style.display = "block";			
		wait.style.zIndex=parseInt(dialog.style.zIndex)-10;
		wait.id=dialogId+"_waitLayer";
		document.body.insertAdjacentElement("BeforeEnd",wait);
	
		wait.style.width=document.body.offsetWidth;
		wait.style.height=document.body.offsetHeight;
	}
}

function setDialogArguments(dialogArguments)
{	
	dialogArgs = dialogArguments;
}

function getDialogArguments()
{
	return dialogArgs;
}


function disableDialogUnderObjs()
{
	var k=0;
	objs = document.all.tags("SELECT");
	len=objs.length;
	
	for(i=0;i<len;i++)
	{
		obj = objs[i];
		//ch = obj.clientHeight;
		//cw = obj.clientWeight;
		//isVisible = obj.visible;
		isDisable = obj.isDisabled;
		if(!isDisable)
		{
			obj.disabled = true;
			disableSelects[k]=obj;
			k++;				
		}
	}
	
	iframeObjs = document.all.tags("IFRAME");	
	ifrLen = iframeObjs.length;		
	for(i=0;i<ifrLen;i++)
	{
		obj = iframeObjs[i];
		
		//alert(obj.visible);if(iframe.visible)
		objs = obj.contentWindow.document.all.tags("SELECT");
		len=objs.length;		
		for(j=0;j<len;j++)
		{
			obj = objs[j];
			isDisable = obj.isDisabled;
			if(!isDisable)
			{
				obj.disabled = true;	
				disableSelects[k]=obj;
				k++;			
			}
		}
	}
}

function ableDialogUnderObjs()
{		
	len=disableSelects.length;
	for(i=0;i<len;i++)
	{
		obj = disableSelects[i];		
		obj.disabled = false;	
	}
	disableSelects = new Array();
}

/**************** END Standard functions for Dialog/window**********************/

/**************** BEGIN Standard functions for moveable**********************/

	var isDragreleaseHold = false;
	
	function moveable_oncontextmenu(ctrlInst)
	{
	}
	
	function moveable_onactivate(ctrlInst)
	{

		el = event.srcElement;

		part = el.mxpart;
		
		switch(part)
		{
			case "first":
				last = ctrlInst.document.getElementById(getPart(ctrlInst,"last").lastbuttonid);
				if(last)
				{
					getPart(last, "table").focus();
					getPart(last, "table").setActive();
				}
				break;
			case "last":
				ti = getPart(ctrlInst, "toggleImage");
				if(ti)
				{
					ti.focus();
					ti.setActive();
				}
				break;
		}
		
		
	}
	function moveable_onkeydown(ctrlInst)
	{
		stopevents=false;
		key = event.keyCode;
		if(key==KEYCODE_TAB && event.ctrlKey==true)	
		{
			event.cancelBubble=true;
			event.returnValue=false;
			return false;
		}
	}
	function moveable_onkeypress(ctrlInst)
	{
		key = event.keyCode;
		switch(key)
		{
			case KEYCODE_ENTER:
				part = event.srcElement.mxpart;
				switch(part)
				{
					default:
						if(!undef(ctrlInst.defaultbutton))
						{
							defid = ctrlInst.defaultbutton;
							
							if(defid && defid==getControl(event.srcElement).id)
								break;

							itemtoclick = document.getElementById(defid);
							itemtoclick.focus();
							itemtoclick.setActive();
 							sendFrontEndEvent("clickDefaultButton", ctrlInst.id);
							event.cancelBubble=true;
							event.returnValue=false;
							return false;
						}
						break;					
				}
				break;
			case 27:
				dc = getPart(ctrlInst,"dialogClose");
				if(dc && dc.disabled!=true)
				{
					dc.click();
					event.cancelBubble=true;
					event.returnValue=false;
				}
				break;
		}
	}

    function moveable_ondragstart(ctrlInst)
    {
        if(event.srcElement.className == "clsPartHead" )
        {
            window.event.returnValue = false;
        }
    }
    
    function moveable_onmousedown(ctrlInst)
    {
		stopevents=false;
    	ev=event;
    	if(!ev)
    		return;
    	if(ev.button==2)
			return;
    	
    		 
        var oEl = event.srcElement;
     
        if(moveable_correctElement(ctrlInst))
        {
        	if(oEl.tagName=="IMG")
        	{
        		oEl=oEl.parentElement;
        	}
        	
			ctrlInst.offsetY = event.offsetY + event.srcElement.offsetTop;
			ctrlInst.offsetX = event.offsetX + event.srcElement.offsetLeft;
			
            ctrlInst.current = ctrlInst;

		    if(ctrlInst.scrollList)
		    {
			    scrollList=ctrlInst.scrollList.split(",");
				for(scrollItem=0;scrollItem<scrollList.length;scrollItem++)
				{
					scrll=document.getElementById(scrollList[scrollItem]);
					if(scrll)
					{
						scrll.style.overflowX="hidden";
						scrll.style.overflowY="hidden";
					}
				}
			}


            if(ctrlInst.dragwindow==null)
	            ctrlInst.dragwindow=ctrlInst.document.getElementById("dragWindow");
    
    		
            movingItem=ctrlInst;
             
            window.document.attachEvent( "onmousemove"  , moveable_fnMove );
            window.document.attachEvent( "onscroll"  , moveable_fnMove );
            window.document.attachEvent( "onmousemove" , moveable_fnCheckState );
            window.document.attachEvent( "onmouseup"    , moveable_releaseHold );
            window.document.attachEvent( "onselectstart", moveable_fnSelect );
          
        }
        
    }
    
	function moveable_showDragWindow(ctrlInst)
	{
		if(showWindowContentsWhileDragging)
		{
			return;
		}
		if(ctrlInst.collapsed)
		{
			ctrlInst.dragwindow.style.height = ctrlInst.cells(0).firstChild.cells(1).offsetHeight;
		}
		else
		{
			ctrlInst.dragwindow.style.height = ctrlInst.clientHeight - 3;
		}
		ctrlInst.dragwindow.style.width = ctrlInst.clientWidth;
		ctrlInst.dragwindow.style.top = event.clientY - ctrlInst.offsetY + window.document.body.scrollTop-2;
		ctrlInst.dragwindow.style.left = event.clientX - ctrlInst.offsetX + window.document.body.scrollLeft-6;
		
		if(ctrlInst.id!="debug_eventwindow" && ctrlInst.id!="debug_eventlog")
		{
        	ctrlInst.dragwindow.style.zIndex=ctrlInst.style.zIndex+1;
        }
        else
        {
        	ctrlInst.dragwindow.style.zIndex=ctrlInst.style.zIndex+1;
        }

		ctrlInst.dragwindow.style.visibility = "visible";
		//ctrlInst.style.visibility="hidden";
	}

	function moveable_hideDragWindow(ctrlInst)
	{
		
		if(showWindowContentsWhileDragging)
			return;
		ctrlInst.dragwindow.style.visibility = "hidden";
		//ctrlInst.style.visibility="visible";
		ctrlInst.dragwindow.style.height = "";
		ctrlInst.dragwindow.style.top = "";
		ctrlInst.dragwindow.style.left = "";
		ctrlInst.dragwindow.style.width = "";
		ctrlInst.dragwindow.zIndex = "";
		
		//ctrlInst.zIndex=parseInt(ctrlInst.zIndex)+1;
		
	}

    
    function moveable_fnMove()
    {
    	isDragreleaseHold=true;
		moveable_showDragWindow(ctrlInst, ctrlInst );
	    ctrlInst = movingItem;
	    if(ctrlInst)
	    {
			if (event.button != 1)
			{
				moveable_releaseHold(ctrlInst);
				return;
			}

			if(showWindowContentsWhileDragging)
			{

				ctrlInst.style.top = event.clientY - ctrlInst.offsetY + window.document.body.scrollTop;  
				ctrlInst.style.left = event.clientX - ctrlInst.offsetX + window.document.body.scrollLeft;
			}
			else
			{
				movingItem.dragwindow.style.top = event.clientY - ctrlInst.offsetY + window.document.body.scrollTop;  
				movingItem.dragwindow.style.left = event.clientX - ctrlInst.offsetX + window.document.body.scrollLeft;
			}
		}
    }
    
    function moveable_releaseHold()
    {
       	event.cancelBubble=true;
	    ctrlInst = movingItem;
	    if(ctrlInst)
	    {
	        window.document.detachEvent( "onmousemove" , moveable_fnMove );
	        window.document.detachEvent( "onscroll" , moveable_fnMove );
	        window.document.detachEvent( "onmousemove" , moveable_fnCheckState );
	        window.document.detachEvent( "onmouseup" , moveable_releaseHold );
	        window.document.detachEvent( "onselectstart", moveable_fnSelect );
			ctrlInst.style.position="absolute";
		
			if(showWindowContentsWhileDragging)
			{
				ctrlInst.top = ctrlInst.dragwindow.style.posTop;
				ctrlInst.left = ctrlInst.dragwindow.style.posLeft;
				if(ctrlInst.saveposition) 
					saveWindowPosition(ctrlInst.id, ctrlInst.top, ctrlInst.left);
				
			}
			else
			{
				if(isDragreleaseHold)
				{
					y=ctrlInst.dragwindow.style.pixelTop;
				    x=ctrlInst.dragwindow.style.pixelLeft-12;
					ctrlInst.style.posTop = y;
					ctrlInst.style.posLeft = x;	
						
					if(ctrlInst.ifrShim!=null)
					{
						ctrlInst.ifrShim.style.posTop = y;
						ctrlInst.ifrShim.style.posLeft = x;	
					}
					
					isDragreleaseHold=false;
				}
			}	
			
		    if(ctrlInst.scrollList)
		    {
		    	lst = ctrlInst.scrollList.split(",");
				for(scrollItem=0;scrollItem<scrollList.length;scrollItem++)
				{
					scrll=document.getElementById(scrollList[scrollItem]);
					if(scrll)
					{
						scrll.style.overflowX="auto";
						scrll.style.overflowY="auto";
					}
				}
			}
		
			if(showWindowContentsWhileDragging)
				return;
				
			moveable_hideDragWindow(ctrlInst); 
		
			
			if(ctrlInst.saveposition) 
				saveWindowPosition(ctrlInst.id, y, x);
		}
    }
		
    function moveable_ondblclick(ctrlInst)
    {
       	event.cancelBubble=true;
		if(moveable_correctElement(ctrlInst))
		{
			togimg = getPart(ctrlInst, "toggleImage");
			dragright = getPart(ctrlInst, "dragright");
			dragleft = getPart(ctrlInst, "dragleft");
			if(ctrlInst.rows(1).style.display=="none")
			{
				//ctrlInst.style.width="";
				ctrlInst.rows(1).style.display="block";
				togimg.src=IMAGE_PATH+"minimizesection.gif";
				collapsed = false;
			}
			else
			{
				wdth = ctrlInst.offsetWidth;
				ctrlInst.rows(1).style.display="none";
				ctrlInst.rows(1).style.height="0";
				ctrlInst.style.backgroundImage="";
				ctrlInst.style.background="transparent";
				togimg.src=IMAGE_PATH+"maximizesection.gif";
				ctrlInst.style.width=wdth;
				collapsed = true;
			}
		}
    }
    
    function moveable_correctElement()
    {
        if(event.srcElement.className != "moveableHead")
        {
            window.event.returnValue = false;
            return false;
        }
        return true;
    }
    

    function moveable_fnCheckState()
    {
    
	     ctrlInst = movingItem;
	    if(ctrlInst)
	    {
	        if( event.button != 1 )
	        	moveable_releaseHold(ctrlInst);
		}
    }

    function moveable_fnSelect()
    {
        return false;
    }
    
    
/**************** END Standard functions for moveable**********************/